#include "UtilRenderFeature.h"
#include <SERender/Resourses/Loader/VertexArrayLoader.h>
#include <SERender/Renderer/Renderer.h>

namespace SEngine
{
    UtilRenderFeature::UtilRenderFeature(Renderer &renderer)
        : RenderFeature(renderer) 
    {
        VertexArrayLoader<3, 2> vaoLoader(std::make_unique<CurrentDrive>());
        vaoLoader.PushVertex({-1.0f, -1.0f, 0.0f, 0.0f, 0.0f});
        vaoLoader.PushVertex({1.0f, -1.0f, 0.0f, 1.0f, 0.0f});
        vaoLoader.PushVertex({1.0f, 1.0f, 0.0f, 1.0f, 1.0f});
        vaoLoader.PushVertex({-1.0f, 1.0f, 0.0f, 0.0f, 1.0f});
        vaoLoader.PushFace({0, 1, 2});
        vaoLoader.PushFace({0, 2, 3});
        m_billboard.SetMesh(std::make_unique<Mesh>(vaoLoader.CreateVertexArray()));
        m_billboard.SetAPIType(DrawAPIType::DrawElements);
        m_billboard.SetMode(ElemMode::TRIANGLES);
    }

    void UtilRenderFeature::DrawBillboard(ResRef<Material> material)
    {
        m_billboard.SetMaterial(material);
        m_renderer.DrawEntity(m_billboard);
        // m_billboard.SetMaterial(nullptr);
    }
}